package com.kuaimacode.kframework.api.service.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kuaimacode.kframework.mybatis.mapper.user.OrderEvaluateMapper;
import com.kuaimacode.kframework.mybatis.models.user.OrderEvaluate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 中元
 * @date 2019/04/08
 */
@Service
public class  OrderEvaluateService extends ServiceImpl<OrderEvaluateMapper, OrderEvaluate> {

    	/**
    	 *  分页查找所有的数据
    	 * @param pageNum 当前页码，从1开始
    	 * @param pageSize  一页显示多少行
    	 * @return
    	 */
    	public PageInfo<OrderEvaluate> findAll(int pageNum, int pageSize) {
    		PageHelper.startPage(pageNum, pageSize);
    		List<OrderEvaluate> datas = baseMapper.selectList(null);
    		return new PageInfo<OrderEvaluate>(datas);
    	}

		/**
		 *  分页查找用户所有的数据
		 * @param pageNum 当前页码，从1开始
		 * @param pageSize  一页显示多少行
		 * @return
		 */
		public PageInfo<OrderEvaluate> findAllByUserId(int pageNum, int pageSize, Long userId) {
			PageHelper.startPage(pageNum, pageSize);
			QueryWrapper<OrderEvaluate> qryWrapper = new QueryWrapper<>();
			qryWrapper.eq("user_id", userId);
			List<OrderEvaluate> datas = baseMapper.selectList(qryWrapper);
			return new PageInfo<OrderEvaluate>(datas);
		}

		/**
		 *  根据订单号查询是否已经评价
		 * @return
		 */
		public List<OrderEvaluate> findByOrderId(Long orderId) {
			QueryWrapper<OrderEvaluate> qryWrapper = new QueryWrapper<>();
			qryWrapper.eq("order_id", orderId);
			List<OrderEvaluate> datas = baseMapper.selectList(qryWrapper);
			return datas;
		}


		/**
		 *  根据订单号查询是否已经评价
		 * @return
		 */
		public OrderEvaluate findOneByOrderId(Long orderId) {
			QueryWrapper<OrderEvaluate> qryWrapper = new QueryWrapper<>();
			qryWrapper.eq("order_id", orderId);
			OrderEvaluate datas = baseMapper.selectOne(qryWrapper);
			return datas;
		}
	/**
	 *  根据交易订单号查询
	 * @return
	 */
	public OrderEvaluate findByOutTradeNo(String outTradeNo) {
		QueryWrapper<OrderEvaluate> qryWrapper = new QueryWrapper<>();
		qryWrapper.eq("out_trade_no", outTradeNo);
		OrderEvaluate data = baseMapper.selectOne(qryWrapper);
		return data;
	}

	/**
	 *  根据交易订单号查询
	 * @return
	 */
	public List<OrderEvaluate> findByMasterId(Long masterId) {
		QueryWrapper<OrderEvaluate> qryWrapper = new QueryWrapper<>();
		qryWrapper.eq("master_id", masterId);
		List<OrderEvaluate> data = baseMapper.selectList(qryWrapper);
		return data;
	}
}

